package org.edu.modules.message.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.message.entity.VeMsgSend;
import org.edu.modules.message.service.IVeMsgDraftsService;
import org.edu.modules.message.service.IVeMsgSendService;
import org.edu.modules.message.vo.MessageVo;
import org.edu.modules.message.vo.MsgSendCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
* @Description: 已发消息
* @Author: jeecg-boot
* @Date:   2021-05-07
* @Version: V1.0
*/
@Api(tags="消息发送")
@RestController
@RequestMapping("/message/veMsgMessage")
@Slf4j
public class VeMsgMessageController extends BaseController<VeMsgSend, IVeMsgSendService> {
   @Autowired
   private IVeMsgSendService veMsgSendService;
   @Autowired
   private IVeMsgDraftsService veMsgDraftsService;


   /**
    *   发送
    *
    * @param messageVo
    * @return
    */
   @AutoLog(value = "发送消息")
   @ApiOperation(value="发送消息", notes="发送消息")
   @PostMapping(value = "/send")
   public Result<?> send(@RequestBody MessageVo messageVo) {
       boolean result = veMsgSendService.send(messageVo);
       if (result) {
           return Result.OK("发送成功！");
       } else {
           return Result.error("发送失败");
       }

   }

    /**
     *   保存草稿箱
     *
     * @param messageVo
     * @return
     */
    @AutoLog(value = "保存草稿箱")
    @ApiOperation(value="保存草稿箱", notes="保存草稿箱")
    @PostMapping(value = "/saveDrafts")
    public Result<?> saveDrafts(@RequestBody MessageVo messageVo) {
        boolean result = veMsgDraftsService.saveDrafts(messageVo);
        if (result) {
            return Result.OK("保存成功！");
        } else {
            return Result.error("保存失败");
        }

    }

}
